import { mapState, mapGetters } from 'vuex'
export default {
  data () {
    return {
      loading: true
    }
  },
  computed: {
    ...mapState([
      'mapArea'
    ]),
    ...mapGetters({
      gardenOverview: 'gardenOverview',
      ageData: 'ageData',
      jobData: 'jobData'
    })
  },
  watch: {
    async mapArea (val) {
      if (val) {
        this.loading = true
        await this.basicFetch()
        await this.refresh()
      }
    }
  },
  mounted () {
    // 初始化所有边框样式
    this.$common.border(window.$('.bottom .content'))
    // 5分钟刷新一次
    this._intervalHandle = setInterval(() => {
      this.refresh()
    }, 300000)
  },
  beforeDestroy () {
    clearInterval(this._intervalHandle)
  },
  methods: {
    toggleLoading (val) {
      val ? window.$('.refresh').find('i').addClass('loading') : window.$('.refresh').find('i').removeClass('loading')
    },
    async basicFetch () {
      await this.$store.dispatch('fetchAreaIdList')
      await this.$store.dispatch('fetchGardenIdList')
      // 当前区域总览数据（幼儿园，教师信息）
      await this.$store.dispatch('fetchGeneralOverview')
    }
  }
}
